Skip to content

fix(core): a sealed preview keeps a clip's picture while its lighter copy is made - #9006

Merged
miguel-heygen merged 6 commits into
mainfrom
fix/sealed-still-shows-at-once
Nov 28, 2026
Merged

miguel-heygen merged 6 commits into
mainfrom
fix/sealed-still-shows-at-once

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

In a sealed project preview (sandbox-origin), a clip that is switching to a lighter copy keeps showing its own frame while the copy is made, as it already does in an open preview. Before, the clip's box went black (only the titles over it) for about 2 seconds.

Why

When the preview steps its quality down, the runtime holds a clip off its file and sets the clip's poster to a still of the clip at the playhead (hf-proxy-still) until the lighter copy is ready. After that reset the browser draws the poster, not the decoded frame, until the clip plays or seeks.

In a sealed frame the browser did not send the poster's image request at all while the frame's copy request was waiting: in the request log it has no send time for the whole wait and is cancelled when the copy lands, about 2 s later. In an open frame the same request is sent at once and answers in about 50 ms. The server is not involved: stills run in their own job pool, and the same URL fetched from the sealed frame at the same moment is sent at once and answers in 44-48 ms.

Related work

None.

How

  • showStill (in packages/core/src/runtime/mediaProxy.ts): in a sealed frame (window.origin === "null", the same test colorGrading.ts uses for an opaque frame) it fetches the still and sets the poster to an object URL of the answer. An open frame sets the poster URL as before, unchanged.
  • An answer counts only for the hold that asked for it: if dropStill ran or a newer still was asked for meanwhile, it is ignored. dropStill revokes the object URL.
  • A failed or refused fetch leaves no poster, as a failed poster image does in an open frame. An answer that arrives after the page set its own poster is ignored.
  • The runtime now remembers the poster its still put up, in both kinds of frame. When the copy swap holds the clip's current frame, it saves "no poster" instead of the runtime's still as the page's own, and dropping the still removes the poster only if it is still the runtime's. Before, if the copy drew its first frame only after a seek, the swap put the dropped still back (a stale still URL in an open frame, a revoked object URL in a sealed one), and dropping the still also removed a poster the page had set meanwhile.
  • The fetch is readable from the sealed frame: the token path already answers a sealed frame's fetch of any preview file with Access-Control-Allow-Origin: null (opaqueFrameLoads.ts).

Before

Sealed preview, a project with one video clip, frames at 1.8, 2.1, 2.4, 2.7 s (top row) and 3.0, 3.3, 3.6, 3.9 s (bottom row) after the click that opens it:

Before: titles on black until the copy lands

After

Same project, same frames:

After: the clip stays on screen

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix:

  • packages/core/src/runtime/mediaProxy.test.ts "in a sealed frame" › "fetches the still and shows it from the answer, then drops it with the copy" (fails on main: the poster is the still URL, not the fetched answer).

  • Same block › "never shows a still that answers after its copy has landed" (fails when the hold check on the answer is removed) and "keeps a poster the page sets while the still is fetched" (fails on main and without the poster check on the answer).

  • "the still a copy waits behind" › "never puts its still back once dropped, when the copy draws only after seeking", for a sealed and an open frame (both fail on main and when the swap saves the runtime's still as the page's poster), and "keeps a poster the page sets while the copy is made" (fails on main and when dropping the still removes any poster).

  • packages/core mediaProxy.test.ts: 109/109, 3 runs in a row.

  • Recorded on a Linux box (Xvfb, CPU throttled 4x), a desktop app built from these packages, the screen recorded at 60 fps. Measured: how long the clip's box shows no picture after the clip first appears. Rounds count only when the machine's load was at most 16 when they started.

open preview sealed preview
before (main) 83 ms 1916 ms
after 117, 83 ms 100, 67 ms

The remaining ~70-120 ms in both modes falls when the clip swaps to the lighter copy. These rounds ran at the first commit; the second commit changes only which poster is put back after the swap, and two more rounds at the head follow in a comment.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 57 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Quarantined, measured but not gated (0)

Unstable (1)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Update at 3b5af22: main merged in, plus two commits after the review head.

  • ce09ec2: a sealed frame shows its fetched still as a data URL, like the held frame's own still, so nothing is left to release. Before this, a clip that left the page after its copy was served but before it drew kept its blob alive. New test: a clip leaving mid-copy drops its still.
  • 6bb6cf1: the still is encoded with the browser's FileReader instead of a script loop (5.3 MB: 822 ms down to 89 ms at 4x CPU slowdown in headless Chromium).

Still sizes with the server's JPEG settings: 4K clips 0.33-1.0 MB, a 4K heavy-grain clip 5.3 MB, an 8K heavy-grain clip 21 MB; about 1.33x that as a data URL. The fetched bytes and Blob are freed once encoded. During the hold the string sits in the runtime's map and the poster attribute; both are cleared after the swap. A smaller still would come from the server making it at preview size, which is out of scope here.

Render suites at 6bb6cf1: engine 3,784 passed; producer unit (vitest) 1,635 passed.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — A clip can keep a large data-URL poster after its copy is served. Once makeCopy() calls loadProxy(), dropStill() waits for loadeddata or error. A clip can leave the page or abandon that media load without either event. If the page retains the element, the poster attribute and stillPosters retain the full encoded image. The new detach regression removes the clip while the copy is still pending, so it exercises the earlier !wanted branch. Please cover detachment after the copy is served and before it draws, and clear the runtime’s still when that load is abandoned while preserving a page-set poster.

The PR body also needs a fails without the fix: line naming the test on that line. The current heading lists tests beneath it. fetches the still and shows it from the answer, then drops it with the copy is already documented as a failing case.

— tai (automated review)

…another file

A copy's still stood until the copy drew or failed. A clip that left the page, or was given another
file, after its copy was served fired neither, so it kept the still (a sealed frame's full image) as
its poster. The wait now also ends on an abort or emptied for another src, and when the clip leaves
the page; a poster the page set is kept.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

fails without the fix: fetches the still and shows it from the answer, then drops it with the copy

fails without the fix: drops its still when the clip leaves the page after its copy is served (origin null)

Update at 6d3e9f5, answering the change request at 3b5af22. After the copy is served, the still now drops on every way that load can end, not only when it draws or fails: an abort or emptied once the clip has another src, and the clip leaving the page (watched only while a copy is waiting to draw). The copy's own load, which fires emptied with the copy's src, keeps it. A poster the page set is kept.

New tests, for both a sealed and an open frame: the clip leaves the page after its copy is served and before it draws; the clip gets another file before its copy draws (its own load's emptied keeps the still). Plus: a poster the page sets is kept when the clip leaves.

  • At 3b5af22: the four leave/new-file tests fail (the still stays as the poster).
  • With the fix broken three ways in turn (leaving not watched; another file ignored; the copy's own load dropping the still), each fails its own test.
  • At 6d3e9f5: mediaProxy.test.ts passes 118/118, 3 runs in a row. Engine 3,784 passed and producer unit 1,635 passed.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The poster cleanup addresses my previous finding. The new tests cover detachment and source replacement after the copy is served, and cover preserving a page-set poster. I reviewed the delta without rerunning the tests.

The remaining blocker is the PR description. Please put fails without the fix: drops its still when the clip leaves the page after its copy is served (origin null) on one line in the description. The author comment already has the evidence, and the description currently has the heading and test names on separate lines.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The head is unchanged at 6d3e9f53. The poster cleanup resolves my code finding, and the author's regression evidence satisfies the review requirement. I verified the evidence without rerunning the tests.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit aa1ed29 Nov 28, 2026
106 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-still-shows-at-once branch November 28, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants